<template>
  <div>
    <h1>自动登录</h1>
  </div>
</template>

<script>
import { getInfo } from '@/api/login'

export default {
  name: 'LoginSso',
  data() {
    return {
      loginRules: {},
      loading: false,
      //验证码开关
      captchaOnOff: true,
      //注册开关
      register: false,
      //重定向
      redirect: undefined
    }
  },
  watch: {},
  created() {
    //页面初始化时调单点登录方法
    this.loginSso()
  },
  methods: {
    loginSso() {
      //获取地址栏中的code
      const username = this.$route.query.username
      //调用登录的接口
      if (username === '' || username === undefined || username === null) {
        //请求中不带code，拦截为正常登录
        console.log('=============>进入正常登录')
      } else {
        console.log('=============>进入自动登录')
        this.loading = true//开启过渡动画
        const loginInfo = {
          'username': username
        }
        console.log('loginInfo============》', loginInfo)
        //执行另一套登录操作
        this.$store.dispatch('LoginSso', loginInfo).then(() => {
          console.log('====================进入方法了')
          this.$message.success('登录成功')
          this.loading = false
          //判断当前角色
          getInfo().then((res) => {
            sessionStorage.setItem('ssUserName', res.user.nickName)
            //处理登录
            this.$router.push({ path: this.redirect || '/' }).catch(() => {
            })
          })
        }).catch(err => {
          console.log('有异常信息', err)
          this.loading = false
        })
      }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">

</style>